package code;

import java.util.Arrays;
import java.util.Scanner;

public class Eatroom_day13 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] table =new int[n];
        for (int i = 0; i < n; i++) {
            table[i]=sc.nextInt();
        }
        int[][] customers=new int[m][2];
        for (int i = 0; i < m; i++) {
            customers[i][0]=sc.nextInt();
            customers[i][1]=sc.nextInt();
        }
        int res=maxMoney(n,m, table,customers);
        System.out.println(res);

    }
    public static int maxMoney(int n, int m, int[] tables, int[][] customers) {
        Arrays.sort(tables);
        Arrays.sort(customers, (a, b) -> b[1] - a[1]);
        boolean[] is_used = new boolean[n];
        for (int i = 0; i < n; i++) {
            is_used[i]=false;
        }
        int sum=0;
        for(int customer[]:customers){
            int customer_num=customer[0];
            int money=customer[1];
            int can=findTable(tables,is_used,customer_num);
            if(can!=-1){
                is_used[can]=true;
                sum+=money;
            }
        }
        return sum;
    }
    public static int findTable(int[] table,boolean[] is_used,int customer_num){
        int left=0,right=table.length-1;
        int res=-1;
        while(left<=right){
            int mid=left+(right-left)/2;
            if(table[mid]>=customer_num){
                res=mid;
                right=mid-1;
            }
            else {
                left=mid+1;
            }
        }
        while(res!=-1&&is_used[res]){
            res=res+1;
            if (res>=table.length||table[res]<customer_num){
                res=-1;
                break;
            }
        }
        return res;
    }
}
